<template>
  <div>
    <el-form ref="form" :model="form">
      <el-form-item label="商品名称" :label-width="formlabelwidth">
        <el-input v-model="form.SkuName"></el-input>
      </el-form-item>
      <el-form-item label="价格" :label-width="formlabelwidth">
        <el-input v-model="form.Price"></el-input>
      </el-form-item>
      <el-form-item label="库存" :label-width="formlabelwidth">
        <el-input v-model="form.Num"></el-input>
      </el-form-item>
      <el-form-item label="预警库存" :label-width="formlabelwidth">
        <el-input v-model="form.Num"></el-input>
      </el-form-item>
      <el-form-item label="商品分类" :label-width="formlabelwidth">
        <el-select v-model="form.CategoryId" placeholder="请选择模板">
          <el-option
            v-for="cate in categorys"
            :key="cate.Id"
            :label="cate.CatName"
            :value="cate.Id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" :label-width="formlabelwidth">
        <el-switch v-model="form.Status" :active-value="1" :inactive-value="0" active-text="上架" inactive-text="下架"></el-switch>
      </el-form-item>
      <el-form-item :label-width="formlabelwidth">
        <el-button type="primary" @click="submit">确认</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import SkuApi from "@/api/SkuApi";
import { mapState } from "vuex";
export default {
  props: ["id"],
  data() {
    return {
      form: {},
      formlabelwidth: "80px",
    };
  },
  computed: {
    ...mapState("category", {
      categorys: (state) => state.categorys,
    }),
  },
  methods: {
    getData() {
      SkuApi.getById(this.id).then((res) => {
        this.form = res.data;
      });
    },
    submit() {
      SkuApi.update(this.form)
      .then(res=>{
        if(res.code==1){
          this.$message({
            message:"修改成功",
            type:"success"
          })
          this.$emit("close")
        }
      })
    },
    cancel() {
      this.$emit("close");
    },
  },
  created() {
    this.getData();
  },
};
</script>

<style>
</style>